package collections;

import util.Tracer;

public class SinglyLinkedListQueue<T> {
	private SinglyLinkedListNode<T> head;
	private SinglyLinkedListNode<T> tail;
	public void enqueue(T t)
	{
		SinglyLinkedListNode<T> node = new SinglyLinkedListNode<T>(t);
		if(tail == null)
		{
			head = tail = node;
		}
		else
		{
			tail.setNext(node);
			tail = node;
		}
	}
	
	public T dequeue()
	{
		SinglyLinkedListNode<T> node = head;
		head = node.getNext();
		if(head == tail)
			tail = null;

		return node.getKey();
	}
	
	public static void main(String[] args) {
		SinglyLinkedListQueue<Integer> q = new SinglyLinkedListQueue<Integer>();
		
		q.enqueue(1);
		q.enqueue(2);

		Tracer.trace(q.dequeue().toString());
		Tracer.trace(q.dequeue().toString());
		
	}
}
